export const getConfiguration = () =>
({
  server: {
    port: process.env.SERVER_PORT
  },
  mysql: {
    host: process.env.MYSQL_HOST,
    port: Number.parseInt(process.env.MYSQL_PORT!, 10),
    user: process.env.MYSQL_USERNAME,
    password: process.env.MYSQL_PASSWORD || process.env.MYSQL_ROOT_PASSWORD || '',
    database: process.env.MYSQL_DATABASE,
  },
  jwt: {
    secretkey: process.env.JWT_SECRETKEY,
    expiresIn: process.env.JWT_EXPIRESIN,
  },
} as const)

export type ConfigurationType = ReturnType<typeof getConfiguration>

type NestedPath<ObjectType extends object> =
  {
    [Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object ? Key | `${Key}.${NestedPath<ObjectType[Key]>}` : `${Key}`
  }[keyof ObjectType & (string | number)]

export type ConfigurationKeys = Record<NestedPath<ConfigurationType>, any>